package com.nhjf.dao.system;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.system.User;
import com.nhjf.pojo.qo.system.UserQo;

@Repository
public class UserDao extends BaseDao<User,UserQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, UserQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null){
			//用户角色,默认为懒加载
			criteria.setFetchMode("roleList", qo.isSeachRole()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getUserName() != null){
				criteria.add(Restrictions.eq("userName", qo.getUserName()));
			}
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("id", qo.getUserId()));
			}

			if(qo.getUserPassword() != null){
				criteria.add(Restrictions.eq("userPassword", qo.getUserPassword()));
			}
			if(qo.getItsusableornot() != null){
				criteria.add(Restrictions.eq("itsusableornot", qo.getItsusableornot()));
			}
			if(qo.getFans()!=null) {
				criteria.add(Restrictions.eq("fans", qo.getFans()));
			}
			if(qo.getFollow()!=null) {
				criteria.add(Restrictions.eq("follow", qo.getFollow()));
			}
		}
		return criteria;
	}

	@Override
	protected Class<User> getEntityClass() {
		// TODO Auto-generated method stub
		return User.class;
	}


}